const readline = require('readline-sync');

function main() {
    console.log("欢迎来玩呐～1. 玩 2. 不玩：");
    let opt = readline.question() - 0;
    if (opt == 1) {
        let computer = random(10, 21); // 电脑点数
        console.log('电脑的：', computer);
        let sum = 0; // 玩家和变量
        let flag = true;
        while (flag) {
            console.log("抽取，1. 抽 2. 不抽：");
            let opt = readline.question() - 0;
            switch (opt) {
                case 1: // 抽
                    let number = random(1, 10); // 玩家抽的每一次的1-10
                    sum += number;
                    if (sum > 21) {
                        sum = -1;
                        judge(computer, sum);
                        flag = false;
                    }
                    console.log(`本次抽到${number},当前总点数：${sum}`);
                    break;
                case 2: //  不抽
                    judge(computer, sum);
                    flag = false;
                    break;
            }
        }
    }
}
main();
// 比较
function judge(computer, user) {
    if (user == -1) { // 死
        console.log("炸死了");
        return;
    }
    if (computer > user) {
        console.log(`电脑:${computer},玩家：${user},电脑赢`);
    } else if (computer == user) {
        console.log("相等");
    } else {
        console.log(`电脑:${computer},玩家：${user},玩家赢`);
    }
}

// 随机数
function random(min, max) {
    if (!max) {
        [max, min] = [min, 0];
    }
    if (min > max) {
        [max, min] = [min, max];
    }
    return parseInt(Math.random() * (max + 1 - min) + min);
}
